<template>
<div>
  <p>注册<input type="text" v-model="form.username"></p>
  <p>密码<input type="text" v-model="form.password"></p>
  <button @click="add">注册</button>
  <br>
  <br>
  <br>
  <p>登录用户<input type="text" v-model="table.username"></p>
  <p>登录密码<input type="text" v-model="table.password"></p>
  <button @click="login">登录</button>
</div>
</template>

<script>
export default {
  name: "day04_login",
  data(){
    return{
      form:{},
      table:{}
    }
  },
  methods:{
    add(){
      this.$axios.post('users/res/',this.form)
      .then(res=>{
        if(res.data.code==200){
          alert('注册成功')
        }else {
          alert('注册失败')
        }
      })
    },
    login(){
      this.$axios.post('users/login/',this.table)
      .then(res=>{
        if(res.data.code==200){
          localStorage.setItem('userid',res.data.userid)
          this.$router.push('day04_news')
        }else {
          alert(res.data.meg)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
